-define(ETS_END,'$end_of_table').
-define(db_options(Record,Index),
         [{index,Index},{attributes, record_info(fields,Record)},{record_name, Record}
          |aleph_config:get_db_options()]
        ).

-define(m_query(QLC),qlc:q(QLC)).

-define(m_orderby3(QLC,Key,Order),
        fun()->
          Handle=?m_query(QLC),
          qlc:keysort(Key,Handle,{order,Order})
        end ()
        ).        

-define(m_orderby(QLC,Compare),        
        fun()->           
            Handle=?m_query(QLC),
            case is_function(Compare) of
                true->                    
                    qlc:sort(Handle,{order,Compare});
                false->
                    qlc:keysort(Compare,Handle)%,{order,ascending})
            end
        end()).

-define(m_result(X),
        fun({atomic,Result})->Result;
           (R)->R  
        end(X) ).

        
-define(retrieve2(Handle,Options),?m_result(mnesia:transaction(fun()->qlc:e(Handle,Options)end))).

-define(retrieve(Handle),?m_result(mnesia:transaction(fun()->qlc:e(Handle)end))).

-define(e_query(QLC),qlc:q(QLC)).
-define(e_retrieve(QLC),?retrieve(qlc:q(QLC))).
